package com.marlsite.datadrivendeco;


import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import com.marlsite.datadrivendeco.primitives.ItemPrimitive;
import com.marlsite.datadrivendeco.renderer.BlockEntityWithoutLevelRenderer;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(DataDrivenDeco.MODID)
public class DataDrivenDeco
{
    // Define mod id in a common place for everything to reference
    public static final String MODID = "datadrivendeco";
    // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
    // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
    // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
    public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);

    public static final BlockEntityWithoutLevelRenderer BEWLR = new BlockEntityWithoutLevelRenderer();

    // PRIMITIVES
    public static final RegistryObject<Block> DATA_DRIVEN_BLOCK = BLOCKS.register("data_driven_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
    public static final RegistryObject<Item> DATA_DRIVEN_BLOCK_ITEM = ITEMS.register("data_driven_block", () -> new BlockItem(DATA_DRIVEN_BLOCK.get(), new Item.Properties()));

    public static final RegistryObject<Item> DATA_DRIVEN_ITEM = ITEMS.register("data_driven_item", () -> new ItemPrimitive(new Item.Properties()));
    // PRIMITIVES

    // BUGGED PRIMITIVES
    public static final RegistryObject<Block> DATA_DRIVEN_BLOCK_BUGGED = BLOCKS.register("data_driven_block_bugged", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
    public static final RegistryObject<Item> DATA_DRIVEN_BLOCK_BUGGED_ITEM = ITEMS.register("data_driven_block_bugged", () -> new BlockItem(DATA_DRIVEN_BLOCK_BUGGED.get(), new Item.Properties()));

    public static final RegistryObject<Item> DATA_DRIVEN_ITEM_BUGGED = ITEMS.register("data_driven_item_bugged", () -> new Item(new Item.Properties()));
    // BUGGED PRIMITIVES

    public static final RegistryObject<CreativeModeTab> PRIMITIVES_TAB = CREATIVE_MODE_TABS.register("primitives", () -> CreativeModeTab.builder()
            .withTabsBefore(CreativeModeTabs.COMBAT)
            .icon(() -> DATA_DRIVEN_ITEM.get().getDefaultInstance())
            .title(Component.translatable("itemGroup." + MODID + ".primitives")) // I couldn't get the language file to work without this line
            .displayItems((parameters, output) -> {
                output.accept(DATA_DRIVEN_BLOCK_ITEM.get());
                output.accept(DATA_DRIVEN_ITEM.get());
                output.accept(DATA_DRIVEN_BLOCK_BUGGED_ITEM.get());
                output.accept(DATA_DRIVEN_ITEM_BUGGED.get());
            }).build());

    public DataDrivenDeco()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        // Register the Deferred Register to the mod event bus so blocks get registered
        BLOCKS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so items get registered
        ITEMS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so tabs get registered
        CREATIVE_MODE_TABS.register(modEventBus);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);

        // Register our mod's ForgeConfigSpec so that Forge can create and load the config file for us
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
    }
}
